package fi.pyppe.android.gps;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;

/**
 * SettingsActivity.
 * 
 * @author Pyppe
 */
public class SettingsActivity extends PreferenceActivity {
  
  public static final int REFRESH_PREFERENCES = 5;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    Preference locationSettingsPreference = (Preference) findPreference("preferenceLocationProviders");
    locationSettingsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
      public boolean onPreferenceClick(Preference preference) {
        startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
        return true;
      }
    });
  }
  
  @Override
  protected void onStop() {
    setResult(REFRESH_PREFERENCES);
    finish();
    super.onStop();
  }

}
